package com.dranie.action;

import com.dranie.entity.User;
import com.jfinal.core.Controller;
import org.apache.commons.lang.StringUtils;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xi
 * Date: 13-8-11
 * Time: AM12:36
 * To change this template use File | Settings | File Templates.
 */
public class AdminController extends Controller {

    public void index() {
        setAttr("hello", "hello world!");
        render("login.html");
    }

    public void main() {
        setAttr("hello", "hello world!");
        User u = (User) getSessionAttr("USER");
        setAttr("u", u);
    }

    public void login() {
        String account = getPara("account");
        String password = getPara("password");
        List<User> list = User.dao.find("select * from user where account = ? and password = ?", account, password);
        if (list != null && !list.isEmpty()) {
            User USER = list.get(0);
            setSessionAttr("USER", USER);
            redirect("main");
        } else {
            if (StringUtils.isNotBlank(account)) {
                setAttr("msg", "用户名或密码无效！");
            }
        }

    }
}

